Skip to content

[chore] Extract provider connections into a shared connections domain#4737

Draft
junaway wants to merge 1 commit into
mainfrom
wp0-connections-extract
Draft

[chore] Extract provider connections into a shared connections domain#4737
junaway wants to merge 1 commit into
mainfrom
wp0-connections-extract

Conversation

@junaway

@junaway junaway commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Context

Provider connections (the OAuth/API-key links to Composio) lived inside the tools domain. Triggers need the same connections, so leaving them in tools would force the new triggers code to import from tools and entangle the two domains. We extract connections into their own domain first, so both tools and triggers depend on it one way.

Changes

Adds a routerless connections domain that owns the shared connection rows and the provider auth verbs:

  • core/connections/ConnectionsService (project-scoped, returns domain DTOs) and ConnectionsGatewayInterface (the provider-keyed adapter port: initiate / get-status / refresh / revoke), implemented by ComposioConnectionsAdapter.
  • dbs/postgres/connections/ConnectionDBE backed by the gateway_connections table, plus DAO and mappings.
  • The migration renames tool_connections to gateway_connections. It lands in the shared core_oss chain so it runs in both editions.

The tools domain no longer owns connections. ToolsService now delegates to ConnectionsService, and the auth verbs were removed from the tools interface and adapter. Nothing in connections imports from tools; the dependency points one way.

The /tools/connections HTTP view is unchanged (its operation_id stays query_tool_connections, part of the frozen OpenAPI contract). It now reads the same gateway_connections rows through the new service.

Tests / notes

  • Tools connection acceptance tests run in both OSS and EE.
  • This is the base lane of the gateway-triggers stack. Everything else builds on it.

…ions domain

Move the provider connection out of /tools into a shared connections domain
(rename tool_connections -> gateway_connections) so triggers can reuse it. The
/tools/connections HTTP contract is unchanged.

- New core/connections (ConnectionsService + ConnectionsGatewayInterface adapter
  port) and dbs/postgres/connections; ToolsService delegates connection mgmt.
- Composio auth verbs move behind ComposioConnectionsAdapter; connections never
  imports tools.
- revoke stays local-only (is_valid=False); cross-domain effect via the shared
  row; usage() reports consumers.
- Migration authored once in core_oss (oss000000002), runs in both editions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 18, 2026 16:13
@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment Jun 18, 2026 4:13pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f7a1300e-7a03-40ae-a8ae-8edd5a530fe1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch wp0-connections-extract

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@junaway junaway changed the title [chore] Extract provider connection into shared routerless connections domain [chore] Extract gateway connections Jun 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Not ready to approve

The PR removes tools connection DTOs/interfaces but leaves the legacy dbs.postgres.tools.dao import path broken (ImportError risk) and the new acceptance tests don’t currently assert DELETE success, so correctness and test signal need tightening before approval.

Pull request overview

This PR extracts provider connection management out of the /tools domain into a new shared, routerless core.connections domain backed by the renamed gateway_connections table, so other domains (e.g. triggers) can reuse the same connection records while keeping the public /tools/connections HTTP contract unchanged.

Changes:

  • Introduces a new core.connections domain (DTOs, service, interfaces, registry) plus a Postgres DAO/DBE mapping for gateway_connections.
  • Splits Composio responsibilities: tool catalog/execution remain in ComposioToolsAdapter, while connection auth verbs move to ComposioConnectionsAdapter.
  • Adds OSS + EE acceptance tests to pin /tools/connections behavior and adds a migration renaming tool_connectionsgateway_connections.
File summaries
File Description
api/oss/tests/pytest/unit/models/test_lifecycle_conventions.py Updates lifecycle conventions list to reference connections DBEs.
api/oss/tests/pytest/acceptance/tools/test_tools_connections.py New OSS acceptance tests for /tools/connections contract.
api/oss/src/dbs/postgres/connections/mappings.py Maps between connection DTOs and gateway_connections DBE.
api/oss/src/dbs/postgres/connections/dbes.py New SQLAlchemy model for gateway_connections.
api/oss/src/dbs/postgres/connections/dao.py New async DAO implementing connection CRUD/query for Postgres.
api/oss/src/dbs/postgres/connections/init.py Package init for new connections DB layer.
api/oss/src/core/tools/service.py Refactors tools service to delegate connection management to ConnectionsService.
api/oss/src/core/tools/providers/composio/adapter.py Removes connection-auth verbs from tools adapter; keeps catalog + execution.
api/oss/src/core/tools/interfaces.py Removes ToolsDAOInterface, leaving only the tools gateway port.
api/oss/src/core/tools/dtos.py Removes tool-connection DTOs and keeps only catalog/call/execution DTOs.
api/oss/src/core/connections/utils.py Renames state helper module docstring for generic connections callbacks.
api/oss/src/core/connections/service.py New service owning connection lifecycle + provider auth orchestration.
api/oss/src/core/connections/registry.py New provider-keyed registry for connection adapters.
api/oss/src/core/connections/providers/composio/adapter.py New Composio adapter for connection auth verbs (initiate/status/refresh/revoke).
api/oss/src/core/connections/providers/composio/init.py Lazy import wrapper for Composio connections adapter.
api/oss/src/core/connections/providers/init.py Package init for connections providers.
api/oss/src/core/connections/interfaces.py Defines DAO + gateway interfaces for the connections domain.
api/oss/src/core/connections/exceptions.py Adds connections-domain exception types.
api/oss/src/core/connections/dtos.py Adds connections-domain DTOs (Connection, create/request/response, usage).
api/oss/src/core/connections/init.py Package init for new connections domain.
api/oss/src/apis/fastapi/tools/router.py Switches OAuth state decode helper import to the connections domain.
api/oss/src/apis/fastapi/tools/models.py Updates /tools/connections request/response models to use Connection* DTOs.
api/oss/databases/postgres/migrations/core_oss/versions/oss000000002_rename_tool_connections_to_gateway_connections.py Adds migration renaming table + constraint/index names.
api/entrypoints/routers.py Wires ConnectionsDAO/Service + Composio connections adapter; updates ToolsService DI; closes new adapters on shutdown.
api/ee/tests/pytest/acceptance/tools/test_tools_connections.py New EE acceptance tests mirroring OSS /tools/connections contract with EE auth gating.
api/ee/tests/pytest/acceptance/tools/init.py Package init for EE tools acceptance tests.

Copilot's findings

Comments suppressed due to low confidence (1)

api/oss/src/core/tools/dtos.py:15

  • ToolConnection / ToolConnectionCreate DTOs were removed from this module, but oss.src.dbs.postgres.tools.dao still imports them. That makes the legacy DAO module fail to import, which can break any remaining callers or tooling that still touches it.
from enum import Enum
from typing import Any, Dict, List, Optional

from agenta.sdk.models.workflows import JsonSchemas
from pydantic import BaseModel

from oss.src.core.shared.dtos import (
    Identifier,
    Json,
    Status,
)

# ---------------------------------------------------------------------------
# Tool Enums
# ---------------------------------------------------------------------------
  • Files reviewed: 22/26 changed files
  • Comments generated: 5

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +20
from abc import ABC, abstractmethod
from typing import List, Optional, Tuple

from oss.src.core.tools.dtos import (
ToolCatalogAction,
ToolCatalogActionDetails,
ToolCatalogIntegration,
ToolCatalogProvider,
ToolExecutionRequest,
ToolExecutionResponse,
)


class ToolsGatewayInterface(ABC):
"""Port for external tool providers (Composio, Agenta, etc.).

Tool-specific verbs only — catalog browse and execution. Connection auth
verbs live behind ``ConnectionsGatewayInterface`` in the connections domain.
"""

Comment on lines +3 to +5

from pydantic import BaseModel

Comment on lines +128 to +130
provider_connection_id: str
redirect_url: Optional[str] = None
connection_data: Dict[str, Any] = {}
Comment on lines +69 to +71
assert revoke.json()["connection"]["flags"]["is_valid"] is False

authed_api("DELETE", f"/tools/connections/{connection_id}")
Comment on lines +150 to +154
revoke = connections_api("POST", f"/tools/connections/{connection_id}/revoke")
assert revoke.status_code == 200, revoke.text
assert revoke.json()["connection"]["flags"]["is_valid"] is False

connections_api("DELETE", f"/tools/connections/{connection_id}")
@jp-agenta jp-agenta changed the title [chore] Extract gateway connections [chore] Extract provider connections into a shared connections domain Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants